using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Random = UnityEngine.Random;

public class AudioManager : MonoBehaviour
{
    //单例模式
    public static AudioManager Instance;
    
    public AudioClip birdCollision;
    public AudioClip birdSelect;
    public AudioClip birdFlying;
    public AudioClip[] pigCollisions;
    public AudioClip woodCollision;
    public AudioClip woodDestoryed;

    private void Awake()
    {
        if (Instance == null)
        {
            Instance = this;
        }
        else
        {
            Destroy(gameObject);
        }
    }

    public void PlayBirdCollison(Vector3 position)
    {
        AudioSource.PlayClipAtPoint(birdCollision, position, 1f);
    }
    
    public void PlayBirdSelect(Vector3 position)
    {
        AudioSource.PlayClipAtPoint(birdSelect, position, 1f);
    }
    
    public void PlayBirdFlying(Vector3 position)
    {
        AudioSource.PlayClipAtPoint(birdFlying, position, 1f);
    }
    
    public void PlayPigCollision(Vector3 position)
    {
        int index = Random.Range(0, pigCollisions.Length);
        AudioSource.PlayClipAtPoint(pigCollisions[index], position, 1f);
    }
    
    public void PlayWoodCollision(Vector3 position)
    {
        AudioSource.PlayClipAtPoint(woodCollision, position, 0.5f);
    }
    
    public void PlayWoodDestroyed(Vector3 position)
    {
        AudioSource.PlayClipAtPoint(woodDestoryed, position, 0.5f);
    }
    
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
